package com.gamatechno.solodestination;

import com.gamatechno.solodestination.model.AppPreferences;

import android.R.color;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.os.Build;

public class PilihBahasa extends Activity {

	LinearLayout llIndo;
	LinearLayout llUS;
	Button btn_pilihbahasa;
	String selected_bahasa = "id";
	AppPreferences _apppref;
	int is_pertama = 0;

	public PilihBahasa() {
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pilih_bahasa);
		// fvcking actionbar//
		Bitmap b = BitmapFactory.decodeResource(getResources(),
				R.drawable.header_img);
		BitmapDrawable bd = new BitmapDrawable(getResources(), b);
		ActionBar ab = getActionBar();
		ab.setBackgroundDrawable(bd);
		LayoutInflater inflater = (LayoutInflater) this
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = inflater.inflate(R.layout.actionbar_logo, null);
		ab.setCustomView(v);
		ab.setDisplayShowCustomEnabled(true);
		ab.setDisplayHomeAsUpEnabled(true);
		ab.setHomeButtonEnabled(false);
		ab.setLogo(R.drawable.ic_home);
		ab.setTitle("");

		Bundle extras = getIntent().getExtras();
		int is_pertamax = extras.getInt("is_pertama");
		if (extras != null) {
			is_pertama = is_pertamax;
		}

		llIndo = (LinearLayout) findViewById(R.id.llIndo);
		llUS = (LinearLayout) findViewById(R.id.llUS);
		btn_pilihbahasa = (Button) findViewById(R.id.btn_pilihbahasa);
		_apppref = new AppPreferences(this);
		selected_bahasa = _apppref.getBahasa();
		setWarna();
		llIndo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				selected_bahasa = "id";
				setWarna();
			}
		});

		llUS.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				selected_bahasa = "us";
				setWarna();
			}
		});

		btn_pilihbahasa.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

				if (is_pertama == 1) {
					_apppref.setBahasa(selected_bahasa);
					_apppref.setIsPertama();
					Intent aa = new Intent(PilihBahasa.this, MainActivity.class);
					aa.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
					startActivity(aa);
					finish();
				} else {
					finish();
				}

				// i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
				// finish();
			}
		});
	}

	public void setWarna() {
		Log.i("selected_bahasa", selected_bahasa);
		if (selected_bahasa.equals("id")) {
			llIndo.setBackgroundColor(Color.CYAN);
			llUS.setBackgroundColor(Color.WHITE);
		} else if (selected_bahasa.equals("us")) {
			llIndo.setBackgroundColor(Color.WHITE);
			llUS.setBackgroundColor(Color.CYAN);
		}
	}

	// @Override
	// public boolean onCreateOptionsMenu(Menu menu) {
	//
	// // Inflate the menu; this adds items to the action bar if it is present.
	// getMenuInflater().inflate(R.menu.pilih_bahasa, menu);
	// return true;
	// }

	// @Override
	// public boolean onOptionsItemSelected(MenuItem item) {
	// // Handle action bar item clicks here. The action bar will
	// // automatically handle clicks on the Home/Up button, so long
	// // as you specify a parent activity in AndroidManifest.xml.
	// int id = item.getItemId();
	// if (id == R.id.action_settings) {
	// return true;
	// }
	// return super.onOptionsItemSelected(item);
	// }

}
